package person.tavion.transaction.produce;

import com.alibaba.fastjson2.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserTestService userTestService;
    /**
     * 测试死信消息的
     */
    @RequestMapping("sendUser")
    public String user(String key){
        //
        String userNo = LocalDateTime.now() +"";

        Map<String,Object> map = new HashMap<>();
        map.put("userNo",userNo);
        map.put("userId","1");
        map.put("userName","admin");
        map.put("userPassword","123456");
        map.put("key",key);
        return userService.sendForTransaction(userNo, JSON.toJSONString(map))+"";

    }
    /**
     * 测试消费是否被不同的组，重复消费
     */
    @RequestMapping("testUser")
    public String testUser(){
        //
        List<Map<String,Object>> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Map<String,Object> map = new HashMap<>();
            map.put("userNo","userNo-"+i);
            map.put("userId","1");
            map.put("userName","admin");
            map.put("userPassword","123456");
            list.add(map);
        }
        return userTestService.send(list);


    }
}
